package com.example.s202404026;

import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;

@RestController
@RequestMapping("/d1")
public class Demo {
    @RequestMapping("/m1")
    public Object method1( Person person) {
        return person.toString();
    }

    @RequestMapping("/m2/{id}/{name}")
    public String method2(@PathVariable Integer id, @PathVariable("name") String userName) {
        return "解析参数id:" + id + ",name:" + userName;
    }

    @RequestMapping("m3")
    public String getFile(@RequestPart("file") MultipartFile file) throws IOException {
        //获取文件名称
        String fileName = file.getOriginalFilename();
        //文件上传到指定路径
        file.transferTo(new File("D:/desktop/file/javaEE/temp/" + fileName));
        return "接收到的文件名称为: " + fileName;
    }
}
